﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Project.dalSql;
using System.Data.SqlClient;
using WISD.Common;
using WISD.DBUtility.DBOperate;

namespace WISD.CarFriend.BLL.OA
{
    public class SubstituteDrivingModule
    {
        #region MaticCode

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("SubstituteDrivingID", "T_CF_OA_SubstituteDriving");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int SubstituteDrivingID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_CF_OA_SubstituteDriving");
            strSql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)
			};
            parameters[0].Value = SubstituteDrivingID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WISD.CarFriend.Model.CFModel.T_CF_OA_SubstituteDriving model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_CF_OA_SubstituteDriving(");
            strSql.Append("Name,EmployeeId,VehicleNo,Address,Destination,Mileage,MobileTel,Remarks,Reviser,ReviseDate,State,Memo1,Memo2,Memo3,Memo4,Memo5,Memo6,Memo7,Memo8)");
            strSql.Append(" values (");
            strSql.Append("@Name,@EmployeeId,@VehicleNo,@Address,@Destination,@Mileage,@MobileTel,@Remarks,@Reviser,@ReviseDate,@State,@Memo1,@Memo2,@Memo3,@Memo4,@Memo5,@Memo6,@Memo7,@Memo8)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@EmployeeId", SqlDbType.NVarChar,50),
					new SqlParameter("@VehicleNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Destination", SqlDbType.NVarChar,100),
					new SqlParameter("@Mileage", SqlDbType.Decimal,9),
					new SqlParameter("@MobileTel", SqlDbType.NVarChar,50),
					new SqlParameter("@Remarks", SqlDbType.NVarChar,500),
					new SqlParameter("@Reviser", SqlDbType.NVarChar,50),
					new SqlParameter("@ReviseDate", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@Memo1", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo2", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo3", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo4", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo5", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo6", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo7", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo8", SqlDbType.NVarChar,100)};
            parameters[0].Value = model.Name;
            parameters[1].Value = model.EmployeeId;
            parameters[2].Value = model.VehicleNo;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Destination;
            parameters[5].Value = model.Mileage;
            parameters[6].Value = model.MobileTel;
            parameters[7].Value = model.Remarks;
            parameters[8].Value = model.Reviser;
            parameters[9].Value = model.ReviseDate;
            parameters[10].Value = model.State;
            parameters[11].Value = model.Memo1;
            parameters[12].Value = model.Memo2;
            parameters[13].Value = model.Memo3;
            parameters[14].Value = model.Memo4;
            parameters[15].Value = model.Memo5;
            parameters[16].Value = model.Memo6;
            parameters[17].Value = model.Memo7;
            parameters[18].Value = model.Memo8;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(WISD.CarFriend.Model.CFModel.T_CF_OA_SubstituteDriving model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_CF_OA_SubstituteDriving set ");
            strSql.Append("Name=@Name,");
            strSql.Append("EmployeeId=@EmployeeId,");
            strSql.Append("VehicleNo=@VehicleNo,");
            strSql.Append("Address=@Address,");
            strSql.Append("Destination=@Destination,");
            strSql.Append("Mileage=@Mileage,");
            strSql.Append("MobileTel=@MobileTel,");
            strSql.Append("Remarks=@Remarks,");
            strSql.Append("Reviser=@Reviser,");
            strSql.Append("ReviseDate=@ReviseDate,");
            strSql.Append("State=@State,");
            strSql.Append("Memo1=@Memo1,");
            strSql.Append("Memo2=@Memo2,");
            strSql.Append("Memo3=@Memo3,");
            strSql.Append("Memo4=@Memo4,");
            strSql.Append("Memo5=@Memo5,");
            strSql.Append("Memo6=@Memo6,");
            strSql.Append("Memo7=@Memo7,");
            strSql.Append("Memo8=@Memo8");
            strSql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@EmployeeId", SqlDbType.NVarChar,50),
					new SqlParameter("@VehicleNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Destination", SqlDbType.NVarChar,100),
					new SqlParameter("@Mileage", SqlDbType.Decimal,9),
					new SqlParameter("@MobileTel", SqlDbType.NVarChar,50),
					new SqlParameter("@Remarks", SqlDbType.NVarChar,500),
					new SqlParameter("@Reviser", SqlDbType.NVarChar,50),
					new SqlParameter("@ReviseDate", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@Memo1", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo2", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo3", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo4", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo5", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo6", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo7", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo8", SqlDbType.NVarChar,100),
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)};
            parameters[0].Value = model.Name;
            parameters[1].Value = model.EmployeeId;
            parameters[2].Value = model.VehicleNo;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Destination;
            parameters[5].Value = model.Mileage;
            parameters[6].Value = model.MobileTel;
            parameters[7].Value = model.Remarks;
            parameters[8].Value = model.Reviser;
            parameters[9].Value = model.ReviseDate;
            parameters[10].Value = model.State;
            parameters[11].Value = model.Memo1;
            parameters[12].Value = model.Memo2;
            parameters[13].Value = model.Memo3;
            parameters[14].Value = model.Memo4;
            parameters[15].Value = model.Memo5;
            parameters[16].Value = model.Memo6;
            parameters[17].Value = model.Memo7;
            parameters[18].Value = model.Memo8;
            parameters[19].Value = model.SubstituteDrivingID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int SubstituteDrivingID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_CF_OA_SubstituteDriving ");
            strSql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)
			};
            parameters[0].Value = SubstituteDrivingID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string SubstituteDrivingIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_CF_OA_SubstituteDriving ");
            strSql.Append(" where SubstituteDrivingID in (" + SubstituteDrivingIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public WISD.CarFriend.Model.CFModel.T_CF_OA_SubstituteDriving GetModel(int SubstituteDrivingID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 SubstituteDrivingID,Name,EmployeeId,VehicleNo,Address,Destination,Mileage,MobileTel,Remarks,Reviser,ReviseDate,State,Memo1,Memo2,Memo3,Memo4,Memo5,Memo6,Memo7,Memo8 from T_CF_OA_SubstituteDriving ");
            strSql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)
			};
            parameters[0].Value = SubstituteDrivingID;

            WISD.CarFriend.Model.CFModel.T_CF_OA_SubstituteDriving model = new WISD.CarFriend.Model.CFModel.T_CF_OA_SubstituteDriving();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["SubstituteDrivingID"] != null && ds.Tables[0].Rows[0]["SubstituteDrivingID"].ToString() != "")
                {
                    model.SubstituteDrivingID = int.Parse(ds.Tables[0].Rows[0]["SubstituteDrivingID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "")
                {
                    model.Name = ds.Tables[0].Rows[0]["Name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["EmployeeId"] != null && ds.Tables[0].Rows[0]["EmployeeId"].ToString() != "")
                {
                    model.EmployeeId = ds.Tables[0].Rows[0]["EmployeeId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["VehicleNo"] != null && ds.Tables[0].Rows[0]["VehicleNo"].ToString() != "")
                {
                    model.VehicleNo = ds.Tables[0].Rows[0]["VehicleNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"].ToString() != "")
                {
                    model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Destination"] != null && ds.Tables[0].Rows[0]["Destination"].ToString() != "")
                {
                    model.Destination = ds.Tables[0].Rows[0]["Destination"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Mileage"] != null && ds.Tables[0].Rows[0]["Mileage"].ToString() != "")
                {
                    model.Mileage = decimal.Parse(ds.Tables[0].Rows[0]["Mileage"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MobileTel"] != null && ds.Tables[0].Rows[0]["MobileTel"].ToString() != "")
                {
                    model.MobileTel = ds.Tables[0].Rows[0]["MobileTel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Remarks"] != null && ds.Tables[0].Rows[0]["Remarks"].ToString() != "")
                {
                    model.Remarks = ds.Tables[0].Rows[0]["Remarks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Reviser"] != null && ds.Tables[0].Rows[0]["Reviser"].ToString() != "")
                {
                    model.Reviser = ds.Tables[0].Rows[0]["Reviser"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ReviseDate"] != null && ds.Tables[0].Rows[0]["ReviseDate"].ToString() != "")
                {
                    model.ReviseDate = DateTime.Parse(ds.Tables[0].Rows[0]["ReviseDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["State"] != null && ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Memo1"] != null && ds.Tables[0].Rows[0]["Memo1"].ToString() != "")
                {
                    model.Memo1 = ds.Tables[0].Rows[0]["Memo1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo2"] != null && ds.Tables[0].Rows[0]["Memo2"].ToString() != "")
                {
                    model.Memo2 = ds.Tables[0].Rows[0]["Memo2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo3"] != null && ds.Tables[0].Rows[0]["Memo3"].ToString() != "")
                {
                    model.Memo3 = ds.Tables[0].Rows[0]["Memo3"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo4"] != null && ds.Tables[0].Rows[0]["Memo4"].ToString() != "")
                {
                    model.Memo4 = ds.Tables[0].Rows[0]["Memo4"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo5"] != null && ds.Tables[0].Rows[0]["Memo5"].ToString() != "")
                {
                    model.Memo5 = ds.Tables[0].Rows[0]["Memo5"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo6"] != null && ds.Tables[0].Rows[0]["Memo6"].ToString() != "")
                {
                    model.Memo6 = ds.Tables[0].Rows[0]["Memo6"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo7"] != null && ds.Tables[0].Rows[0]["Memo7"].ToString() != "")
                {
                    model.Memo7 = ds.Tables[0].Rows[0]["Memo7"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Memo8"] != null && ds.Tables[0].Rows[0]["Memo8"].ToString() != "")
                {
                    model.Memo8 = ds.Tables[0].Rows[0]["Memo8"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SubstituteDrivingID,Name,EmployeeId,VehicleNo,Address,Destination,Mileage,MobileTel,Remarks,Reviser,ReviseDate,State,Memo1,Memo2,Memo3,Memo4,Memo5,Memo6,Memo7,Memo8 ");
            strSql.Append(" FROM T_CF_OA_SubstituteDriving ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" SubstituteDrivingID,Name,EmployeeId,VehicleNo,Address,Destination,Mileage,MobileTel,Remarks,Reviser,ReviseDate,State,Memo1,Memo2,Memo3,Memo4,Memo5,Memo6,Memo7,Memo8 ");
            strSql.Append(" FROM T_CF_OA_SubstituteDriving ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM T_CF_OA_SubstituteDriving ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.SubstituteDrivingID desc");
            }
            strSql.Append(")AS Row, T.*  from T_CF_OA_SubstituteDriving T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion


        #region SelfCode

        /// <summary>
        ///  初始化页面和查询数据
        /// </summary>
        /// <param name="pageSize">每页显示的条数</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="condition">搜索条件</param>
        /// <returns></returns>
        public static string GetData(int pageSize, int pageIndex, string condition)
        {
            StringBuilder tableName = new StringBuilder(); //从哪些表里面进行查询
            tableName.Append(" T_CF_OA_SubstituteDriving a ");
            string order = " a.SubstituteDrivingID desc ";  //排序的字段
            StringBuilder fields = new StringBuilder(); //返回的列
            fields.Append(" a.SubstituteDrivingID main,a.Memo3 as driveId,a.Name,a.VehicleNo,a.MobileTel")
                        .Append(",case a.State when 0 then '未审核' when 1  then '已审核' when 2  then '已完成' else '' end State");
            StringBuilder where = new StringBuilder(); //查询的条件
            where.Append(" 1=1 ");
            if (condition != "")
            {
                string[] array = condition.Split('@');
                string name = array[0];
                string state = array[1];
                string vehicleNo = array[2];
                if (name.Trim() != "null")
                {
                    where.AppendFormat("  and a.Name like N\'%{0}%\' ", name);
                }
                if (state.Trim() != "null")
                {
                    where.AppendFormat("  and a.State={0}  ", state);
                }
                if (vehicleNo.Trim() != "null")
                {
                    where.AppendFormat("  and a.VehicleNo=N\'{0}\'  ", vehicleNo);
                }
            }
            object[] objectArray = new object[] { tableName.ToString(), fields.ToString(), order, pageSize, pageIndex, where };
            DataTable dt = new DataTable();
            int recordCount = 0;
            dt = dalSqlHelper.ExecuteProcedure(objectArray, ref recordCount);
            if (dt.Rows.Count > 0)
            {
                return dalSqlHelper.DtToSON(dt) + "@" + recordCount.ToString();
            }
            else
            {
                return "@0";
            }
        }


        /// <summary>
        /// 查询指定主键对应的记录
        /// </summary>
        /// <param name="pk"></param>
        /// <returns></returns>
        public static string GetOne(string pk)
        {
            StringBuilder tableName = new StringBuilder(); //从哪些表里面进行查询
            tableName.Append(" T_CF_OA_SubstituteDriving a ");
            string order = " a.SubstituteDrivingID desc ";  //排序的字段
            StringBuilder fields = new StringBuilder(); //返回的列
            fields.Append(" a.SubstituteDrivingID,a.Name,a.EmployeeId,a.VehicleNo,a.Address,a.Destination,a.Mileage,a.MobileTel,a.Remarks,a.Reviser,")
                    .Append("a.ReviseDate,a.State,a.Memo1 as ReserveDate,a.Memo2 as ArriveDate,a.Memo3 as DriveId,a.Memo4,a.Memo5,a.Memo6,a.Memo7,a.Memo8 ");
            StringBuilder where = new StringBuilder(); //查询的条件
            where.AppendFormat(" a.SubstituteDrivingID=N\'{0}\' ", pk);
            object[] objectArray = new object[] { tableName.ToString(), fields.ToString(), order, 1, 1, where };
            DataTable dt = new DataTable();
            int recordCount = 0;
            dt = dalSqlHelper.ExecuteProcedure(objectArray, ref recordCount);
            if (dt.Rows.Count > 0)
            {
                return dalSqlHelper.DtToSON(dt);
            }
            else
            {
                return "";
            }
        }


        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="dictionary"></param>
        /// <returns></returns>
        public static string AddEntity(IDictionary<string, string> dictionary)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into T_CF_OA_SubstituteDriving(");
            sql.Append("Name,VehicleNo,Address,Destination,Mileage,MobileTel,Remarks,Reviser,ReviseDate,State,Memo1,Memo2,Memo3,Memo4,Memo5,Memo6,Memo7,Memo8,EmployeeId)");
            sql.Append(" values (");
            sql.Append("@Name,@VehicleNo,@Address,@Destination,@Mileage,@MobileTel,@Remarks,@Reviser,@ReviseDate,@State,@Memo1,@Memo2,@Memo3,@Memo4,@Memo5,@Memo6,@Memo7,@Memo8,@EmployeeId)");
            SqlParameter[] parameters = {
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@VehicleNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Destination", SqlDbType.NVarChar,100),
					new SqlParameter("@Mileage", SqlDbType.Decimal,9),
					new SqlParameter("@MobileTel", SqlDbType.NVarChar,50),
					new SqlParameter("@Remarks", SqlDbType.NVarChar,500),
					new SqlParameter("@Reviser", SqlDbType.NVarChar,50),
					new SqlParameter("@ReviseDate", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@Memo1", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo2", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo3", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo4", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo5", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo6", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo7", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo8", SqlDbType.NVarChar,100),
                    new SqlParameter("@EmployeeId", SqlDbType.NVarChar,50)};
            parameters[0].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Name");
            parameters[1].Value = StringHandle.GetDictionaryValue<string>(dictionary, "VehicleNo");
            parameters[2].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Address");
            parameters[3].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Destination");
            parameters[4].Value = StringHandle.GetDictionaryValue<double>(dictionary, "Mileage");
            parameters[5].Value = StringHandle.GetDictionaryValue<string>(dictionary, "MobileTel");
            parameters[6].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Remarks");
            parameters[7].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Reviser");
            parameters[8].Value = StringHandle.GetDictionaryValue<DateTime>(dictionary, "ReviseDate");
            parameters[9].Value = StringHandle.GetDictionaryValue<int>(dictionary, "State");
            parameters[10].Value = StringHandle.GetDictionaryValue<string>(dictionary, "ReserveDate");    //预约时间
            parameters[11].Value = StringHandle.GetDictionaryValue<string>(dictionary, "ArriveDate");    //到达时间
            parameters[12].Value = StringHandle.GetDictionaryValue<string>(dictionary, "DriveId");    //代驾编号
            parameters[13].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo4");
            parameters[14].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo5");
            parameters[15].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo6");
            parameters[16].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo7");
            parameters[17].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo8");
            parameters[18].Value = StringHandle.GetDictionaryValue<string>(dictionary, "EmployeeId");

            SqlObject sqlObject = new SqlObject();
            sqlObject.Sql = sql.ToString();
            sqlObject.PramS = parameters;
            List<SqlObject> sqlObjectList = new List<SqlObject>();
            sqlObjectList.Add(sqlObject);

            if (dalSqlHelper.ExecuteTransaction(sqlObjectList))
            {
                return "Success";
            }
            else
            {
                return "Failure";
            }
        }


        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="pk"></param>
        /// <returns></returns>
        public static string DeleteEntity(string pk)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from T_CF_OA_SubstituteDriving ");
            sql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)
			};
            parameters[0].Value = pk;

            SqlObject sqlObject = new SqlObject();
            sqlObject.Sql = sql.ToString();
            sqlObject.PramS = parameters;
            List<SqlObject> sqlObjectList = new List<SqlObject>();
            sqlObjectList.Add(sqlObject);

            if (dalSqlHelper.ExecuteTransaction(sqlObjectList))
            {
                return "Success";
            }
            else
            {
                return "Failure";
            }
        }


        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="dictionary"></param>
        /// <returns></returns>
        public static string EditEntity(IDictionary<string, string> dictionary)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("update T_CF_OA_SubstituteDriving set ");
            sql.Append("Name=@Name,");
            sql.Append("VehicleNo=@VehicleNo,");
            sql.Append("Address=@Address,");
            sql.Append("Destination=@Destination,");
            sql.Append("Mileage=@Mileage,");
            sql.Append("MobileTel=@MobileTel,");
            sql.Append("Remarks=@Remarks,");
            sql.Append("Reviser=@Reviser,");
            sql.Append("ReviseDate=@ReviseDate,");
            sql.Append("State=@State,");
            sql.Append("Memo1=@Memo1,");
            sql.Append("Memo2=@Memo2,");
            sql.Append("Memo3=@Memo3,");
            sql.Append("Memo4=@Memo4,");
            sql.Append("Memo5=@Memo5,");
            sql.Append("Memo6=@Memo6,");
            sql.Append("Memo7=@Memo7,");
            sql.Append("Memo8=@Memo8,");
            sql.Append("EmployeeId=@EmployeeId");
            sql.Append(" where SubstituteDrivingID=@SubstituteDrivingID");
            SqlParameter[] parameters = {
					new SqlParameter("@Name", SqlDbType.NVarChar,50),
					new SqlParameter("@VehicleNo", SqlDbType.NVarChar,50),
					new SqlParameter("@Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Destination", SqlDbType.NVarChar,100),
					new SqlParameter("@Mileage", SqlDbType.Decimal,9),
					new SqlParameter("@MobileTel", SqlDbType.NVarChar,50),
					new SqlParameter("@Remarks", SqlDbType.NVarChar,500),
					new SqlParameter("@Reviser", SqlDbType.NVarChar,50),
					new SqlParameter("@ReviseDate", SqlDbType.DateTime),
					new SqlParameter("@State", SqlDbType.Int,4),
					new SqlParameter("@Memo1", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo2", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo3", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo4", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo5", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo6", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo7", SqlDbType.NVarChar,100),
					new SqlParameter("@Memo8", SqlDbType.NVarChar,100),
                    new SqlParameter("@EmployeeId", SqlDbType.NVarChar,50),
					new SqlParameter("@SubstituteDrivingID", SqlDbType.Int,4)};
            parameters[0].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Name");
            parameters[1].Value = StringHandle.GetDictionaryValue<string>(dictionary, "VehicleNo");
            parameters[2].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Address");
            parameters[3].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Destination");
            parameters[4].Value = StringHandle.GetDictionaryValue<double>(dictionary, "Mileage");
            parameters[5].Value = StringHandle.GetDictionaryValue<string>(dictionary, "MobileTel");
            parameters[6].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Remarks");
            parameters[7].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Reviser");
            parameters[8].Value = StringHandle.GetDictionaryValue<DateTime>(dictionary, "ReviseDate");
            parameters[9].Value = StringHandle.GetDictionaryValue<int>(dictionary, "State");
            parameters[10].Value = StringHandle.GetDictionaryValue<string>(dictionary, "ReserveDate");    //预约时间
            parameters[11].Value = StringHandle.GetDictionaryValue<string>(dictionary, "ArriveDate");    //到达时间
            parameters[12].Value = StringHandle.GetDictionaryValue<string>(dictionary, "DriveId");    //代驾编号
            parameters[13].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo4");
            parameters[14].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo5");
            parameters[15].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo6");
            parameters[16].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo7");
            parameters[17].Value = StringHandle.GetDictionaryValue<string>(dictionary, "Memo8");
            parameters[18].Value = StringHandle.GetDictionaryValue<string>(dictionary, "EmployeeId");
            parameters[19].Value = StringHandle.GetDictionaryValue<string>(dictionary, "SubstituteDrivingID");

            SqlObject sqlObject = new SqlObject();
            sqlObject.Sql = sql.ToString();
            sqlObject.PramS = parameters;
            List<SqlObject> sqlObjectList = new List<SqlObject>();
            sqlObjectList.Add(sqlObject);

            if (dalSqlHelper.ExecuteTransaction(sqlObjectList))
            {
                return "Success";
            }
            else
            {
                return "Failure";
            }
        }


        /// <summary>
        /// 获取代驾编号
        /// </summary>
        /// <returns></returns>
        public static string GetDriveId()
        {
            return DateTime.Now.ToString("yyyyMMddHHmmss");
        }


        /// <summary>
        /// 获取员工信息
        /// </summary>
        /// <returns></returns>
        public static string GetEmployee()
        {
            SqlObject sqlobj = new SqlObject();
            sqlobj.Sql = "select EmployeeID,Name from T_CF_OA_Employee where 1=@one ";
            sqlobj.PramS = new SqlParameter[] { 
               new SqlParameter("@one",1)
            };
            DataTable dt = dalSqlHelper.ExecuteSelect(sqlobj);
            return dalSqlHelper.DtToSON(dt);
        }

        #endregion
    }
}
